﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MLevel.API.Samples.SharePointWebPart.Models;
using System.Linq;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Net.Http;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using System.Web.Script.Serialization;


namespace MLevel.API.Samples.SharePointWebPart.mLevel.SharePointWebPart
{
    public partial class mLevelUserControl : UserControl
    {
        #region Class Members

        private static string source { get; set; }

        private static string playerApiUrl { get; set; }

        private static string groupApiUrl { get; set; }

        #endregion

        #region Page Events

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Page.DataBind();
            }
        }

        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);

            this.HideUserControls();

            // GET Mission Catalogue Data first and bind to UI
            var missionsNavData = this.GetMissionsData().Result;
            MissionRepeater.DataSource = missionsNavData;
            MissionRepeater.DataBind();

            if (!string.IsNullOrEmpty(playerApiUrl))
            {

                LeaderboardHeader.Visible = true;
                MissionImage.Visible = true;
                RenderMissionOrActivityLeaderboards(missionsNavData);
            }

            if (!string.IsNullOrEmpty(groupApiUrl))
            {
                GroupLeaderboardHeadingContainer.Visible = true;
                catalogueDiv.Visible = false;
                MissionRepeater.Visible = false;
                MissionGroupDiv.Visible = true;


                var groupLeaderboardModel = this.GetGroupLeaderboard(groupApiUrl).Result;
                MissionGroupsGridview.DataSource = groupLeaderboardModel.GroupsData;
                MissionGroupsGridview.DataBind();
                GroupLeaderboardName.Text = groupLeaderboardModel.GroupName;
                GroupLeaderboardPaging.Text = string.Format("Displaying top {0} of {1}", groupLeaderboardModel.GroupsDisplayed, groupLeaderboardModel.TotalGroups);
                groupApiUrl = string.Empty;
            }
        }

        private void HideUserControls()
        {
            LeaderboardHeader.Visible = false;
            GroupLeaderboardHeadingContainer.Visible = false;
            catalogueDiv.Visible = false;
            CurrentUserDataTable.Visible = false;
            MissionGroupDiv.Visible = false;
            MissionImage.Visible = false;
        }

        #endregion
        private void RenderMissionOrActivityLeaderboards(List<MissionCatalogueModel> MissionsNavData)
        {
            var activities = new List<ActivityCatalogueModel>();
            var groups = new List<GroupCatalogueModel>();
            var uriList = new List<string>(playerApiUrl.Split('/'));
            if (uriList.Contains("MissionLeaderboards"))
            {
                var index = uriList.IndexOf("MissionLeaderboards");
                var missionID = uriList[index + 1];
                var missionCatalogueModel = MissionsNavData.Where(m => m.ID == missionID).FirstOrDefault();

                activities = missionCatalogueModel.Activities;
                groups = missionCatalogueModel.Groups;
                MissionImage.ImageUrl = string.Format("{0}/{1}/?X-MLevel-AuthToken={1}", "https://sc-ml-leaderboard-dev.sc-app.com/Images/Index", missionCatalogueModel.imageID, "{{API TOKEN}}");
            }

            if (uriList.Contains("ActivityLeaderboards"))
            {
                var index = uriList.IndexOf("ActivityLeaderboards");
                var activityID = uriList[index + 1];
                var missionCatalogueModel = MissionsNavData.Where(m => m.Activities.Select(a => a.ID).Contains(activityID)).FirstOrDefault();

                activities = missionCatalogueModel.Activities;
                groups = missionCatalogueModel.Groups;
            }

            var missionLeaderboardModel = this.GetMissionLeaderboard(playerApiUrl).Result;


            this.MissionLeaderboardBindingHelper(missionLeaderboardModel, groups, activities);

            LeadersGridView.DataSource = missionLeaderboardModel.PlayersData;
            LeadersGridView.DataBind();
        }

        private void MissionLeaderboardBindingHelper(MissionLeaderboardModel missionLeaderboardModel, IList<GroupCatalogueModel> groups, IList<ActivityCatalogueModel> activities)
        {
            if (missionLeaderboardModel.GroupName != "Everyone")
            {

                groups.Add(new GroupCatalogueModel { Name = "Everyone", Url = "https://sc-ml-leaderboard-dev.sc-app.com/api/MissionLeaderboards/" + missionLeaderboardModel.ID.ToString() });
            }

            // this.MissionLeaderboardBindingHelper(missionLeaderboardModel);

            ActivitySideNavRepeater.DataSource = activities;
            GroupTopNav.DataSource = groups;
            ActivitySideNavRepeater.DataBind();
            GroupTopNav.DataBind();

            CurrentUserDataTable.Visible = true;
            var rankNameLabel = CurrentUserDataTable.FindControl("RankNameLabel") as Label;
            rankNameLabel.Text = string.Format("{0} {1}", missionLeaderboardModel.CurrentPlayer.Rank, missionLeaderboardModel.CurrentPlayer.DisplayName);
            var currentUserPointsLabel = CurrentUserDataTable.FindControl("CurrentUserPointsLabel") as Label;
            currentUserPointsLabel.Text = missionLeaderboardModel.CurrentPlayer.Score.ToString() + " pts";
            var currentUserStarsLabel = CurrentUserDataTable.FindControl("CurrentUserStarsLabel") as Label;
            currentUserStarsLabel.Text = missionLeaderboardModel.CurrentPlayer.Stars.ToString() + " stars";

            PagingLabel.Text = string.Format("Showing {0} of {1} Players", missionLeaderboardModel.PlayersDisplayed, missionLeaderboardModel.TotalPlayers);
            GroupLabel.InnerText = missionLeaderboardModel.GroupName + " |";
            TitleLabel.InnerText = missionLeaderboardModel.Name;
            catalogueDiv.Visible = true;
            MissionRepeater.Visible = false;
            MissionGroupDiv.Visible = false;
            playerApiUrl = string.Empty;
        }

        #region API Calls and Data Access

        public async Task<MissionLeaderboardModel> GetMissionLeaderboard(string baseUri)
        {
            using (var client = new HttpClient())
            {
                var spContext = SPContext.Current.Web.CurrentUser;
                var userName = spContext.LoginName.Split('\\')[1];
                var baseUrl = string.Format("{0}/?userName={1}", baseUri, userName);
                var requestMessage = new HttpRequestMessage(HttpMethod.Get, baseUrl);
                requestMessage.Headers.Add("X-MLevel-AuthToken", "{{API TOKEN}}");

                var response = await client.SendAsync(requestMessage);
                var stringifiedResponse = response.Content.ReadAsStringAsync().Result;

                var javascriptSerializer = new JavaScriptSerializer();
                var jsonData = javascriptSerializer.DeserializeObject(stringifiedResponse) as Dictionary<string, object>;
                var leaderboardModel = this.GetLeaderboardModel(jsonData);

                return leaderboardModel;
            }

        }

        public async Task<GroupLeaderboardModel> GetGroupLeaderboard(string baseUri)
        {
            using (var client = new HttpClient())
            {
                var requestMessage = new HttpRequestMessage(HttpMethod.Get, baseUri);
                requestMessage.Headers.Add("X-MLevel-AuthToken", "{{API TOKEN}}");

                var response = await client.SendAsync(requestMessage);
                var stringifiedResponse = response.Content.ReadAsStringAsync().Result;

                var javascriptSeralizer = new JavaScriptSerializer();
                var jsonData = javascriptSeralizer.DeserializeObject(stringifiedResponse) as Dictionary<string, object>;
                var groupModel = this.GetGroupLeaderboardModel(jsonData);

                return groupModel;
            }
        }

        public async Task<List<MissionCatalogueModel>> GetMissionsData()
        {
            using (var client = new HttpClient())
            {
                var requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://sc-ml-leaderboard-dev.sc-app.com/api/missions");
                requestMessage.Headers.Add("X-MLevel-AuthToken", "{{API TOKEN}}");

                var response = await client.SendAsync(requestMessage);
                var stringifiedResponse = response.Content.ReadAsStringAsync().Result;

                var javascriptSerializer = new JavaScriptSerializer();
                var jsonData = javascriptSerializer.DeserializeObject(stringifiedResponse) as Dictionary<string, object>;
                return GetMissionCatalogue(jsonData);
            }
        }

        #endregion

        #region JSON to POCO conversion Helpers

        private List<MissionCatalogueModel> GetMissionCatalogue(Dictionary<string, object> jsonData)
        {
            var missions = jsonData["missions"];
            var collection = missions as System.Collections.IEnumerable;
            var missionsList = new List<MissionCatalogueModel>();
            if (collection != null)
            {
                var missionsArray = (object[])collection;
                foreach (Dictionary<string, object> missionData in missionsArray)
                {
                    var model = new MissionCatalogueModel
                    {
                        ID = (string)missionData["id"],
                        Name = (string)missionData["name"],
                        Url = (string)missionData["url"],
                        imageID = (string)missionData["imageID"]
                    };

                    var activities = missionData["activities"];
                    var activityCollection = activities as System.Collections.IEnumerable;
                    if (activityCollection != null)
                    {
                        var activityArray = (object[])activityCollection;
                        foreach (Dictionary<string, object> activityData in activityArray)
                        {
                            var activityModel = new ActivityCatalogueModel
                            {
                                Name = (string)activityData["name"],
                                Url = (string)activityData["url"],
                                ID = (string)activityData["id"]
                            };

                            var activityGroups = activityData["groups"];
                            var activityGroupCollection = activityGroups as System.Collections.IEnumerable;
                            if (activityGroupCollection != null)
                            {
                                var activityGroupArray = (object[])activityGroupCollection;
                                foreach (Dictionary<string, object> activityGroupData in activityGroupArray)
                                {
                                    var activityGroupModel = new GroupCatalogueModel
                                    {
                                        Name = (string)activityGroupData["name"],
                                        Url = (string)activityGroupData["url"]
                                    };
                                    activityModel.Groups.Add(activityGroupModel);
                                }
                            }

                            model.Activities.Add(activityModel);
                        }
                    }

                    var missionGroups = missionData["groups"];
                    var missionGroupCollection = missionGroups as System.Collections.IEnumerable;
                    if (missionGroupCollection != null)
                    {
                        var missionGroupArray = (object[])missionGroupCollection;
                        foreach (Dictionary<string, object> missionGroupData in missionGroupArray)
                        {
                            var groupModel = new GroupCatalogueModel
                            {
                                Name = (string)missionGroupData["name"],
                                Url = (string)missionGroupData["url"]
                            };

                            model.Groups.Add(groupModel);
                        }
                    }

                    missionsList.Add(model);
                }
            }
            return missionsList;
        }

        private GroupLeaderboardModel GetGroupLeaderboardModel(Dictionary<string, object> dic)
        {
            var Model = new GroupLeaderboardModel
            {
                ID = (string)dic["id"],
                Name = (string)dic["name"],
                TotalGroups = (int)dic["totalGroups"],
                GroupsDisplayed = (int)dic["groupsDisplayed"],
                // MaxScore = (int)dic["maxScore"],
                GroupID = (string)dic["groupID"],
                GroupName = (string)dic["groupName"]
            };

            object output;
            if (dic.TryGetValue("groupsData", out output))
            {
                Model.GroupsData = this.BuildGroupData(output);
            }

            object maxScore;
            if (dic.TryGetValue("maxScore", out maxScore))
            {
                Model.MaxScore = (int)maxScore;
            }

            return Model;

        }

        private MissionLeaderboardModel GetLeaderboardModel(Dictionary<string, object> dic)
        {
            var model = new MissionLeaderboardModel()
            {
                GroupID = (string)dic["groupID"],
                ID = (string)dic["id"],
                Name = (string)dic["name"],
                IndexOfFirstPlayer = (int?)dic["indexOfFirstPlayer"],
                TotalPlayers = (int?)dic["totalPlayers"],
                PlayersDisplayed = (int?)dic["playersDisplayed"],
                MaxScore = (int?)dic["maxScore"],
                //MaxStars = (int?)dic["maxStars"],
                GroupName = (string)dic["groupName"],
                StartIndex = (int?)dic["startIndex"],
                CurrentItemCount = (int?)dic["currentItemCount"],
                ItemsPerPage = (int?)dic["itemsPerPage"],
                NextLink = (string)dic["nextLink"],
                PreviousLink = (string)dic["previousLink"],
                PagingLinkTemplate = (string)dic["pagingLinkTemplate"]
            };

            var currentPlayer = dic["currentPlayer"] as Dictionary<string, object>;
            var playerData = new PlayerData
            {
                Rank = (int?)currentPlayer["rank"],
                CustomerUserCustomerProductID = (string)currentPlayer["customerUserCustomerProductID"],
                //DisplayName = (string)currentPlayer["displayName"],
                Score = (int?)currentPlayer["score"],
                Stars = (int?)currentPlayer["stars"],
                Duration = (int?)currentPlayer["duration"]
            };

            object displayName = "";
            playerData.DisplayName = currentPlayer.TryGetValue("displayName", out displayName) ? displayName.ToString() : "";

            model.CurrentPlayer = playerData;
            object maxStars = 0;
            if (dic.TryGetValue("maxStars", out maxStars))
            {
                model.MaxStars = (int?)maxStars;
            }
            object output;
            dic.TryGetValue("playersData", out output);
            var playersList = this.BuildPlayerData(output);
            model.PlayersData.AddRange(playersList);

            return model;
        }

        private List<GroupData> BuildGroupData(object dicArray)
        {
            var groupData = new List<GroupData>();
            var collection = dicArray as System.Collections.IEnumerable;

            if (collection != null)
            {
                var apiGroups = (object[])collection;
                foreach (var entry in apiGroups)
                {
                    var groupDic = (Dictionary<string, object>)entry;
                    var group = new GroupData
                    {
                        Rank = (int)groupDic["rank"],
                        DisplayName = (string)groupDic["displayName"],
                        AverageScore = (int)groupDic["averageScore"],
                        Url = (string)groupDic["url"]
                    };
                    object totalMLevel;
                    object averageStars;
                    object percentMLevel;
                    object participation;
                    object participtation; //YOU REALLY NEED TO FIX THIS IN THE CONTRACT!!!!!

                    if (groupDic.TryGetValue("totalmLevel", out totalMLevel))
                    {
                        group.TotalMLevel = (int)totalMLevel;
                    }

                    if (groupDic.TryGetValue("totalmLevel", out averageStars))
                    {
                        group.AverageStars = (int)averageStars;
                    }

                    if (groupDic.TryGetValue("totalmLevel", out percentMLevel))
                    {
                        group.PercentMLevel = (int)percentMLevel;
                    }

                    if (groupDic.TryGetValue("participtation", out participtation))
                    {
                        group.Participation = (int)participtation;
                    }

                    if (groupDic.TryGetValue("participation", out participation))
                    {
                        group.Participation = (int)participation;
                    }


                    groupData.Add(group);
                }
                return groupData;
            }
            return groupData;
        }

        private List<PlayerData> BuildPlayerData(object dicArray)
        {
            var playersData = new List<PlayerData>();
            var collection = dicArray as System.Collections.IEnumerable;

            if (collection != null)
            {
                var apiPLayers = (object[])collection;
                foreach (var entry in apiPLayers)
                {
                    var playerDic = (Dictionary<string, object>)entry;
                    var player = new PlayerData
                    {
                        Rank = (int?)playerDic["rank"],
                        CustomerUserCustomerProductID = (string)playerDic["customerUserCustomerProductID"],
                        DisplayName = (string)playerDic["displayName"],
                        Score = (int?)playerDic["score"],
                        Stars = (int?)playerDic["stars"],
                        Duration = (int?)playerDic["duration"],
                        // ActivitiesPlayed = (int?)playerDic["activitiesPlayed"],
                        // MLevel = (bool)playerDic["mLevel"]
                    };
                    object activitiesPlayed;
                    object MLevel;
                    if (playerDic.TryGetValue("activitiesPlayed", out activitiesPlayed))
                    {
                        player.ActivitiesPlayed = (int?)activitiesPlayed;
                    }

                    if (playerDic.TryGetValue("mLevel", out MLevel))
                    {
                        player.MLevel = (bool)MLevel;
                    }

                    playersData.Add(player);
                }
                return playersData;
            }
            return playersData;
        }

        #endregion

        #region User Control Events

        #region MissionRepeater Events

        protected void MissionRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Image missionImage = e.Item.FindControl("MissionImage") as Image;
                missionImage.ImageUrl = string.Format("{0}/{1}/?X-MLevel-AuthToken={1}", "https://sc-ml-leaderboard-dev.sc-app.com/Images/Index", ((MissionCatalogueModel)e.Item.DataItem).imageID, "{{API TOKEN}}");
                LinkButton missionButton = e.Item.FindControl("MissionButton") as LinkButton;
                missionButton.Text = ((MissionCatalogueModel)e.Item.DataItem).Name;
                missionButton.CommandArgument = ((MissionCatalogueModel)e.Item.DataItem).Url;

                Repeater activityRepeater = e.Item.FindControl("ActivityRepeater") as Repeater;
                var activitiesDataSource = ((MissionCatalogueModel)e.Item.DataItem).Activities;
                if (activitiesDataSource.Count > 0)
                {
                    activityRepeater.DataSource = activitiesDataSource;
                    activityRepeater.DataBind();
                }

                Repeater groupRepeater = e.Item.FindControl("GroupRepeater") as Repeater;
                var groupsDataSource = ((MissionCatalogueModel)e.Item.DataItem).Groups;
                if (groupsDataSource.Count > 0)
                {
                    groupRepeater.DataSource = groupsDataSource;
                    groupRepeater.DataBind();
                }
            }
        }

        protected void MissionRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                playerApiUrl = e.CommandArgument.ToString();
                Page.DataBind();
            }
        }

        #endregion

        #region ActivityRepeater Events

        protected void ActivityRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinkButton activityButton = e.Item.FindControl("ActivityButton") as LinkButton;
                activityButton.Text = ((ActivityCatalogueModel)e.Item.DataItem).Name;
                activityButton.CommandArgument = ((ActivityCatalogueModel)e.Item.DataItem).Url;

                Repeater activityGroupRepeater = e.Item.FindControl("ActivityGroupRepeater") as Repeater;
                var activityGroupDataSource = ((ActivityCatalogueModel)e.Item.DataItem).Groups;
                if (activityGroupDataSource.Count > 0)
                {
                    activityGroupRepeater.DataSource = activityGroupDataSource;
                    activityGroupRepeater.DataBind();
                }
            }
        }

        protected void ActivityRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                playerApiUrl = e.CommandArgument.ToString();
                Page.DataBind();
            }
        }

        #endregion

        #region GroupRepeater Events

        protected void GroupRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                groupApiUrl = e.CommandArgument.ToString();
                Page.DataBind();
            }
        }

        protected void GroupRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Button groupButton = e.Item.FindControl("GroupButton") as Button;
                groupButton.Text = ((GroupCatalogueModel)e.Item.DataItem).Name;
                groupButton.CommandArgument = ((GroupCatalogueModel)e.Item.DataItem).Url;
            }
        }

        #endregion

        #region MissionGroupsGridView Events

        protected void MissionGroupsGridview_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton missionGroupFieldButton = e.Row.FindControl("MissionGroupFieldButton") as LinkButton;
                missionGroupFieldButton.Text = ((GroupData)e.Row.DataItem).DisplayName;
                missionGroupFieldButton.CommandArgument = ((GroupData)e.Row.DataItem).Url;

                var groupPointsLabel = e.Row.FindControl("GroupPointsLabel") as Label;
                groupPointsLabel.Text = ((GroupData)e.Row.DataItem).AverageScore.ToString() + " pts";
                var groupParticipantsLabel = e.Row.FindControl("GroupParticipantsLabel") as Label;
                groupParticipantsLabel.Text = ((GroupData)e.Row.DataItem).Participation.ToString() + " participants";
            }
        }

        protected void MissionGroupsGridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "View")
            {
                playerApiUrl = e.CommandArgument.ToString();
                Page.DataBind();
            }
        }

        #endregion

        #region ActivityGroupRepeater Events

        protected void ActivityGroupRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                groupApiUrl = e.CommandArgument.ToString();
                Page.DataBind();
            }
        }

        protected void ActivityGroupRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Button activityGroupButton = e.Item.FindControl("ActivityGroupButton") as Button;
                activityGroupButton.Text = ((GroupCatalogueModel)e.Item.DataItem).Name;
                activityGroupButton.CommandArgument = ((GroupCatalogueModel)e.Item.DataItem).Url;
            }
        }

        #endregion

        #region ActivitySideNav Event1s

        protected void ActivitySideNavRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var actSideNavLabel = e.Item.FindControl("ActivitySideNavLabel") as Label;
                actSideNavLabel.Text = ((ActivityCatalogueModel)e.Item.DataItem).Name;
                var actSideNavHidden = e.Item.FindControl("ActivitySideNavHidden") as HiddenField;
                actSideNavHidden.Value = ((ActivityCatalogueModel)e.Item.DataItem).Url;

            }
        }

        protected void ActivitySideNavAnchor_ServerClick(object sender, EventArgs e)
        {
            var element = sender as System.Web.UI.HtmlControls.HtmlAnchor;
            var namingContainer = element.NamingContainer as RepeaterItem;

            var hidden = namingContainer.FindControl("ActivitySideNavHidden") as HiddenField;
            playerApiUrl = hidden.Value;

            Page.DataBind();
        }

        #endregion

        #region GroupTopNav

        protected void GroupTopNav_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label groupTopNavLabel = e.Item.FindControl("GroupTopNavLabel") as Label;
                groupTopNavLabel.Text = ((GroupCatalogueModel)e.Item.DataItem).Name;
                var groupTopNavHidden = e.Item.FindControl("GroupTopNavHidden") as HiddenField;
                groupTopNavHidden.Value = ((GroupCatalogueModel)e.Item.DataItem).Url;
            }
        }



        protected void GroupTopNavAnchor_ServerClick(object sender, EventArgs e)
        {
            var element = sender as System.Web.UI.HtmlControls.HtmlAnchor;
            var namingContainer = element.NamingContainer as DataListItem;

            var hidden = namingContainer.FindControl("GroupTopNavHidden") as HiddenField;
            if (!hidden.Value.Contains("Groups"))
            {
                playerApiUrl = hidden.Value;
            }
            else
            {
                groupApiUrl = hidden.Value;
            }

            Page.DataBind();
        }

        #endregion

        #region Button Click Events

        protected void navButton_Click(object sender, EventArgs e)
        {
            Response.Redirect(this.ResolveUrl(Request.Url.AbsolutePath));
        }

        #endregion

        #endregion
    }
}
